#include "main-program.h"
#include "widget-container.h"
#include "function-list.h"
#include <stdlib.h>
#include <string.h>

main_program_t* main_program_new_with_login(login_widget_t* login_widget){
	//init
	main_program_t* result = malloc(sizeof(main_program_t));
	result->login_widget = login_widget;

	result->controls = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(result->controls), "Hedspi student manager");
	g_signal_connect_swapped(G_OBJECT(result->controls), "destroy", G_CALLBACK(main_program_destroy), result);

	//init function list
	function_list_t* function_list = function_list_new();
	result->function_list = function_list;
	widget_container_show(*function_list);

	//add function
	function_list_add(function_list, "_Print smt", "Print hello world context", G_CALLBACK(g_print), "Hello world");
	function_list_add(function_list, "_Quit", "Exit the program", G_CALLBACK(gtk_widget_destroy), widget_container_get_controls(*result));
	
	//add to main win
	gtk_container_add(
			GTK_CONTAINER(result->controls),
			widget_container_get_controls(*function_list));

	return result;
}

void main_program_destroy(main_program_t* main_program){
	widget_container_destroy(main_program);
	gtk_widget_destroy(widget_container_get_controls(*main_program->login_widget));
	free(main_program);
}
